//  This file is part of Swordbible - http://www.swordwarrior.net
//  Copyright (C) 2003-2009 Manu Mital mital.manu@gmail.com

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2, or (at your option)
//  any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


// SaveSearchResults.cpp : implementation file
//

#include <stdafx.h>
#include "SwordBible.h"
#include "SaveVerseRange.h"


// CSaveVerseRange dialog

IMPLEMENT_DYNAMIC(CSaveVerseRange, CDialog)

CSaveVerseRange::CSaveVerseRange(CWnd* pParent /*=NULL*/)
	: CDialog(CSaveVerseRange::IDD, pParent)
	
{

}

CSaveVerseRange::~CSaveVerseRange()
{
}

void CSaveVerseRange::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_EXISTINGVL, ExistingVLcombo);
	DDX_Control(pDX, IDC_EDIT_VL_NAME, m_newListEditCtrl);
}


BEGIN_MESSAGE_MAP(CSaveVerseRange, CDialog)
	ON_BN_CLICKED(IDOK, &CSaveVerseRange::OnBnClickedOk)
	ON_BN_CLICKED(IDC_RADIO_NEWLIST, &CSaveVerseRange::OnRadioNewList)
	ON_BN_CLICKED(IDC_RADIO_EXISTINGLIST, &CSaveVerseRange::OnRadioExisting)
	ON_BN_CLICKED(IDCANCEL, &CSaveVerseRange::OnCancel)
END_MESSAGE_MAP()


// CSaveVerseRange message handlers

void CSaveVerseRange::OnBnClickedOk()
{

	// check the radio button 1 (new verse list name)
    CButton* pWnd = (CButton *) GetDlgItem(IDC_RADIO_NEWLIST);

	// the user wants to add the verses to a new verse list
	if(pWnd->GetSafeHwnd() && pWnd->GetCheck() == TRUE)
	{
		m_newListEditCtrl.UpdateData(TRUE);
		m_newListEditCtrl.GetWindowText(listName);
	
		if(listName.GetLength() < 3 || listName.GetLength() > 25)
		{
			AfxMessageBox(_T("List Name must be between 3 and 25 characters"));
			listName = _T("");
			m_newListEditCtrl.SetWindowText(_T(""));
			return;

		}

		OnOK();
		return;
	}

	pWnd = (CButton *) GetDlgItem(IDC_RADIO_EXISTINGLIST);

	if(pWnd->GetSafeHwnd() && pWnd->GetCheck() == TRUE)
	{
		listName = _T("");
		ExistingVLcombo.GetLBText( ExistingVLcombo.GetCurSel(), listName);
		OnOK();
		return;


	}

	return;
}

BOOL CSaveVerseRange::OnInitDialog()
{
	CDialog::OnInitDialog();

	listName = _T("");

	int count = ListNames.GetCount();

	for(int i = 0; i < count; i++)
		ExistingVLcombo.AddString(ListNames.GetAt(i) );

	ExistingVLcombo.SetCurSel(0);

	// check the radio button 1 (new verse list name)
    CButton* pWnd = (CButton *) GetDlgItem(IDC_RADIO_NEWLIST);
	if(pWnd->GetSafeHwnd()) pWnd->SetCheck(TRUE);

	m_newListEditCtrl.EnableWindow(TRUE);
	ExistingVLcombo.EnableWindow(FALSE);


	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CSaveVerseRange::OnRadioNewList()
{
	m_newListEditCtrl.SetWindowText(_T(""));  // clear the list name text in the edit control

	m_newListEditCtrl.EnableWindow(TRUE);
	ExistingVLcombo.EnableWindow(FALSE);
	
}

void CSaveVerseRange::OnRadioExisting()
{

	m_newListEditCtrl.SetWindowText(_T(""));   // clear the list name text in the edit control

	m_newListEditCtrl.EnableWindow(FALSE);
	ExistingVLcombo.EnableWindow(TRUE);

	
}

void CSaveVerseRange::OnCancel()
{
	CDialog::OnCancel();
	
}
